package com.shirley.algorithm.sort;

import java.util.Arrays;

public class InsertSort extends SortBase {
    public static int[] sort(int[] source) {
        int[] arr = Arrays.copyOf(source, source.length);
        for (int i = 1; i < arr.length; ) {
            int k = i;
            while (k > 0 && arr[k] < arr[k - 1]) {
                swap(arr, k, k - 1);
                k--;
            }
            i++;
        }
        return arr;
    }
}
